package com.qczl.pme.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qczl.core.controller.BaseController;
import com.qczl.model.Json;
import com.qczl.pme.service.TopicService;
import com.qczl.pme.vo.TopicVo;

/**
 * 主题类型控制器
 * @author SongR
 *
 */
@Controller
@RequestMapping(value = "/topic")
public class TopicController extends BaseController {
	Logger log = Logger.getLogger(this.getClass());

	@Autowired
	TopicService service;
	
	/**
	 * 添加默认主题及类型
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/default", method = { RequestMethod.GET, RequestMethod.POST })
	public Json addDefault() {
		// TODO 添加默认
		Json j = new Json();

		return j;
	}

	/**
	 * 获取会议主题
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/metting/v1", method = { RequestMethod.GET, RequestMethod.POST })
	public Json getMettingV1(int start, int size) {
		Json j = new Json();
		try {
			List<TopicVo> vos = service.getTopicV1(1,start,size);
			j.setLength(new Long(vos.size()));
			if(vos.size()>0){
				j.setMsg("成功获取会议主题！");
				j.setResult(vos);
				j.setSize(service.countTopicV1(1));
			}else{
				j.setMsg("暂无会议主题！");
			}
		} catch (Exception e) {
			j.setMsg("获取会议主题接口异常！");
			j.setSuccess(false);
			log.error("接口异常！", e);
		}
		return j;
	}

	/**
	 * 获取直播主题
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/live/v1", method = { RequestMethod.GET, RequestMethod.POST })
	public Json getLiveV1(int start, int size) {
		Json j = new Json();
		try {
			List<TopicVo> vos = service.getTopicV1(2,start,size);
			j.setLength(new Long(vos.size()));
			if(vos.size()>0){
				j.setMsg("成功获取直播主题！");
				j.setResult(vos);
				j.setSize(service.countTopicV1(2));
			}else{
				j.setMsg("暂无直播主题！");
			}
		} catch (Exception e) {
			j.setMsg("获取直播主题接口异常！");
			j.setSuccess(false);
			log.error("接口异常！", e);
		}
		return j;
	}

	/**
	 * 获取会议类型
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/type/v1", method = { RequestMethod.GET, RequestMethod.POST })
	public Json getTypeV1(String pid, int start, int size) {
		Json j = new Json();
		try {
			List<TopicVo> vos = service.getTypeV1(pid,start,size);
			j.setLength(new Long(vos.size()));
			if(vos.size()>0){
				j.setMsg("成功获取类型！");
				j.setResult(vos);
				j.setSize(service.countTypeV1(pid));
			}else{
				j.setMsg("暂无类型！");
			}
		} catch (Exception e) {
			j.setMsg("获取类型接口异常！");
			j.setSuccess(false);
			log.error("接口异常！", e);
		}
		return j;
	}

}
